package com.i8office.android.zhihuixinwu.module.presenter;

import android.text.TextUtils;

import com.cyan.tools.callback.SimpleCallback;
import com.i8office.android.zhihuixinwu.module.contract.CalendarContract;
import com.i8office.android.zhihuixinwu.module.model.CalendarModel;
import com.i8office.android.zhihuixinwu.ui.schedule.LeaderData;
import com.i8office.android.zhihuixinwu.ui.schedule.ScheduleData;

import java.util.HashMap;
import java.util.Map;

public class LeaderScheduleByNamePresenter extends BasePresenterImpl<CalendarContract.LeaderScheduleByNameView> implements CalendarContract.LeaderScheduleByNamePresenter {
    private CalendarContract.Model model;

    public LeaderScheduleByNamePresenter(CalendarContract.LeaderScheduleByNameView view) {
        super(view);
        model = new CalendarModel();
    }

    @Override
    public void getGroupLeaderData() {
        addDisposable(model.getGroupLeadersData(new SimpleCallback<LeaderData>(mView) {
            @Override
            public void requestError(String msg) {
                super.requestError(msg);
                if (!TextUtils.isEmpty(msg))
                    mView.toast(msg);
            }

            @Override
            public void requestSuccess(LeaderData data) {
                mView.showGroupLeaderData(data.relations);
            }
        }));
    }

    @Override
    public void getLeaderScheduleByName(String uid, String date, String dateOfCurrentMonday) {
        Map<String, String> params = new HashMap<>();
        params.put("uid", uid);
        params.put("date", date);
        if (!TextUtils.isEmpty(dateOfCurrentMonday)){
            params.put("dateOfCurrentMonday", dateOfCurrentMonday);
        }
        addDisposable(model.getLeaderScheduleByName(new SimpleCallback<ScheduleData>(mView) {
            @Override
            public void requestError(String msg) {
                super.requestError(msg);
                if (!TextUtils.isEmpty(msg))
                    mView.toast(msg);
            }

            @Override
            public void requestSuccess(ScheduleData data) {
                mView.showLeaderScheduleByName(data);
            }
        }, params));
    }
}
